@extends('home.index')
@section('body')
    <div class="container">
        <div class="loginTit">
            <div class="area">
                <h3>用户登录</h3>
                <p class="righttit">您还没有账号？<a href="{{url('reg')}}">请注册</a></p>
            </div>
        </div>
        <div class="wf100">
            <div class="logincontent">
                <form name="" id="login" onsubmit="return dologin(this)">
                    {{csrf_field()}}
                    <div class="login-form">
                        <div class="item">
                            <label class="name">账号:</label>
                            <div class="input">
                                <input type="text" name="account" id="account"/>
                            </div>
                            <label class="tips"></label>
                        </div>
                        <div class="item">
                            <label class="name">密码:</label>
                            <div class="input">
                                <input type="password" name="pswd" id="pswd"/>
                            </div>
                            <label class="tips"></label>
                        </div>
                        <div class="item" style="text-align: center;">
                            <input type="submit" value="登录" id="reg" class="submit"/>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('myjs')
    <script src="{{asset('js/jquery.min.js')}}"></script>
    <script>
        function dologin(form) {
            console.log(form);
            $.ajax({
                type: "post",
                url: '/login',
                data: $(form).serializeArray(),
                success: function(result) {
                    if (result == 1) {
                        alert('登录成功');
                        window.location.href="/";
                    }
                    if (result == 2) {
                        alert('用户名密码错误');
                    }
                    if (result == 3) {
                        alert('账户名密码为空');
                    }
                }
            });
            return false;
        }
    </script>
@endsection